package red.lixiang.controller;

import red.lixiang.model.BaseInfo;
import red.lixiang.service.ListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

@Controller
public class ListController {

    @Autowired
    private ListService listService;


    @GetMapping("/list/showList")
    public String showList(@RequestParam(required = false, defaultValue = "0") String type ,Model model){

        BaseInfo baseInfo = listService.getPromotionProductByType(type);
        Map<String , Object > map  = (Map<String, Object>) baseInfo.getObject();
        model.addAttribute("products",map.get("products"));
        return "prolist";
    }

    @GetMapping("/list/getListByKeyWord/{keyWord}")
    public String getListByKeyWord(@PathVariable String keyWord,Model model){
        BaseInfo baseInfo = listService.getProductByKeyWord(keyWord);
        model.addAttribute("products",baseInfo.getObject());
        return "list_macro";
    }
}
